﻿using HualongExcel.Classes;
using Newtonsoft.Json;
using System.IO;

namespace HualongExcel.Utilities
{
    public static class TemplateHelper
    {
        public static void Savetemplate(string path, templateData data)
        {
            var json = JsonConvert.SerializeObject(data);//序列化对象成json
            File.WriteAllText(path, json);//写到本地文件
        }
        public static templateData Loadtemplate(string path)
        {
            if(string.IsNullOrEmpty(path))
                return null;
            if (File.Exists(path))
            {
                try
                {
                    var jsonText = File.ReadAllText(path);
                    return JsonConvert.DeserializeObject<templateData>(jsonText);
                }
                catch (System.Exception e)
                {
                    System.Windows.Forms.MessageBox.Show(e.Message);
                    return null;
                }
            }

            return null;
        }

    }
}
